<admintpl file="header"/>
<script type="text/javascript" src="__PUBLIC__/js/jquery.cityselect.js"></script>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('Admin/AdminUser/index')}">管理员列表</a></li>
        <li class="active"><a href="{:U('Admin/AdminUser/adminUserAdd')}">添加{$Title}</a></li>
    </ul> 
    <form method="post" class="form-horizontal js-ajax-form" id="form.js-ajax-forms"
          action="{:U('Admin/AdminUser/adminUserPost')}">
          
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">*姓名</label>
            <div class="span3" ><input type="text" style="width: 556px;" name="real_name"  ></div>
        </div>
        
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">*账号</label>
            <div class="span3" ><input type="text" style="width: 556px;" name="username" ></div>
        </div>
        
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">*密码</label>
            <div class="span3" ><input type="password" style="width: 556px;" name="admin_pwd" ></div>
        </div>
        
        
        
        
     	<div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 90px;">一、新闻业务</label>
         	</div>
    	</div>
    	<?php 
    		if($role_data['column_role_count'] > 0){
    	?>
    	<div class="control-group">
            <label class="span1 control-label" style="width: 90px;">常规栏目：</label>
            <div class="span3" style="width:800px;">
            	<?php
            		foreach($role_data['column_role'] as $column_key=>$column_value){
            	?>
                <input name="column_checbox[]"   type="checkbox"   value="{$column_value.column_id}"  />{$column_value.name}&nbsp;&nbsp;&nbsp;
                <?php
                	}
            	?>
            </div>
        </div>
    	<?php 
    		}
    	?>
    	
    	
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">本地栏目</label>
            <div class="span3">
                <input type="text" style="width: 556px;" name="area" id="area" readonly="readonly">
            </div>
        </div>



        
        <div class="control-group">
            <label class="span1 control-label" style="width: 90px;"></label>
            <div class="span3">
				<foreach name="established_area_data" key="key" item="value">
				<!-- 分组(开始) -->
				<div class="span3">
				<?php 
					switch($key){
						case 1:
							echo 'ABCDE';
							break;
						case 2:
							echo 'FGHIJ';
							break;
						case 3:
							echo 'KLMNO';
							break;
						case 4:
							echo 'PQRST';
							break;
						case 5:
							echo 'UVWXYZ';
							break;
					}
				?>
					<p></p>
					<!-- 拼音首字母(开始) -->
					<foreach name="value" key="key1" item="value1">
						<div class="span3">
						{$key1}&nbsp;&nbsp;
							<div class="span3">
							<foreach name="value1" key="key2" item="value2">
							<input name="area_checbox"  area_name="{$value2.name}" type="checkbox"   value="{$value2.area_id}"  />{$value2.name}&nbsp;&nbsp;&nbsp;
							</foreach>
							</div>
						</div>
					</foreach>
					<!-- 拼音首字母(结束) -->
				</div>
				<!-- 分组(结束) -->
				</foreach>
            </div>
       
        </div>
                    
                
        <?php 
    		if($role_data['sys_menu_role_count'] > 0){
    	?>            
     	<div class="control-group">  
         	<div class="span3">
                 <label class="span1 control-label" style="width: 100px;"></label>
				<div class="span3" style="width:800px;">二、其他业务：
					<?php
	            		foreach($role_data['sys_menu_role'] as $sys_menu_key=>$sys_menu_value){
            		?>
	                	<input name="sys_menu_checbox[]"   type="checkbox"   value="{$sys_menu_value.menu_id}"  />{$sys_menu_value.name}&nbsp;&nbsp;&nbsp;
	                <?php
	                	}
            		?>
				</div>
         	</div>
    	</div>
		<?php
			}
		?>

		<?php if(count($all_company) > 0){ ?>
		<div class="control-group">
			<div class="span3">
				<label class="span1 control-label" style="width: 100px;"></label>
				<div id="city_1" class="span3" style="width:800px;">三、所属公司：
					<select class="prov" name="prov"></select>
					<select class="city" name="city" id="city" disabled="disabled"></select>
					<select class="company_name" name="company_id"></select>
				</div>
			</div>
		</div>
		<?php } ?>
        <?php if(count($role_info) > 0){ ?>
        <div class="control-group">
            <div class="span3">
                <label class="span1 control-label" style="width: 100px;"></label>
                <div class="span3" style="width:800px;">四、所属角色：
                    <?php
	            		foreach($role_info as $key=>$val){
                    ?>
                    <input name="role_checbox[]"   type="checkbox"   value="{$val.role_id}"  />{$val.role_name}&nbsp;&nbsp;&nbsp;
                    <?php
	                	}
            		?>
                </div>
            </div>
        </div>
        <?php } ?>
		<input type="hidden" name="area_hidden_ids" id="area_hidden_ids" value="">
		<input type="hidden" name="role_hidden_ids" id="role_hidden_ids" value="">
        <div class="form-actions" style="padding-left:260px;">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            &nbsp;&nbsp;<a class="btn" href="{:U('Admin/AdminUser/index')}">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script>
$(function(){
    var prov = '{$company_info.prov}' ? '{$company_info.prov}' : '北京';
    var city = '{$company_info.city}' ? '{$company_info.city}' : '东城区';
    var company_id = '{$company_info.company_id}';

    $("#city_1").citySelect({
        url: "/public/js/city.js",
        prov: prov, //省份
        city: city, //城市
        nodata:"none" //当子集无数据时，隐藏select
    });

    //获取默认地区下的公司
    var data = {city: city};
    $.ajax({
        url: "{:U('PeopleManagement/getCompanyList')}",
        type: "POST",
        data: data,
        dataType: 'json',
        success: function (res) {
            var str = '';
            $('.company_name').children().remove();
            str += '<option name="company" value="0">请选择</option>';
            $.each(res, function (k, v) {
                if(v.company_id){
                    if(company_id == v.company_id){
                        str += '<option name="company" selected="selected" value="'+v.company_id+'">'+v.name+'</option>';
                    }else{
                        str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                    }

                }
            })
			console.log(str)
            $('.company_name').append(str);
        },

        error: function () {
            alert('网络异常，请检查网络后重试');
        }
    });

    $('#city').change( function () {
        var city = $('#city').val();
        $.ajax({
            url: "{:U('PeopleManagement/getCompanyList')}",
            type: "POST",
            data: {city: city},
            dataType: 'json',
            success: function (res) {
                var str = '';
                $('.company_name').children().remove();
                $.each(res, function (k, v) {
                    if(v.company_id){
                        str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                    }
                })
                $('.company_name').append(str);
            },

            error: function () {
                alert('网络异常，请检查网络后重试');
            }
        });
    })

    $('.prov').bind('change', function () {
        setTimeout(function () {
            var city = $('#city').val();
            if(!city){return false}
            $.ajax({
                url: "{:U('PeopleManagement/getCompanyList')}",
                type: "POST",
                data: {city: city},
                dataType: 'json',
                success: function (res) {
                    var str = '';
                    $('.company_name').children().remove();
                    $.each(res, function (k, v) {
                        if(v.company_id){
                            str += '<option name="company" value="'+v.company_id+'">'+v.name+'</option>';
                        }
                    })
                    $('.company_name').append(str);
                },

                error: function () {
                    alert('网络异常，请检查网络后重试');
                }
            });
        }, 50)
    })

	$("[name='area_checbox']").click(function(){
		var area_id = $(this).val();
		var area_name = $(this).attr('area_name');
		
		var area_hidden_ids = $("#area_hidden_ids").val();
		var area_values = $("#area").val();
		
		var ids_arr = area_hidden_ids.split(",");          
		var values_arr = area_values.split(",");   
		
		if(ids_arr.indexOf(area_id) == '-1'){
			area_hidden_ids+=area_id+',';
			area_values+=area_name+',';
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==area_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			area_hidden_ids = ids_arr.join(",");
			area_values = values_arr.join(",");
			$("#area").val(area_values);
			$("#area_hidden_ids").val(area_hidden_ids);
		}
	})
	
	$("[name='administrator_checbox']").click(function(){
		var administrator_id = $(this).val();
		var administrator_name = $(this).attr('administrator_name');
		
		var administrator_hidden_ids = $("#administrator_hidden_ids").val();
		var administrator_values = $("#administrator").val();
		
		var ids_arr = administrator_hidden_ids.split(",");         
		var values_arr = administrator_values.split(",");   
		
		if(ids_arr.indexOf(administrator_id) == '-1'){
			administrator_hidden_ids+=administrator_id+',';
			administrator_values+=administrator_name+',';
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==administrator_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			administrator_hidden_ids = ids_arr.join(",");
			administrator_values = values_arr.join(",");
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}
	})

})
</script>
</body>
</html>